//
//  ArrayIsEmptyTransformer.m
//  Penda
//
//  Created by Duckjin Kang on 1/4/10.
//  Copyright 2010 StonyBrookUniv.. All rights reserved.
//

#import "ArrayIsEmptyTransformer.h"


@implementation ArrayIsEmptyTransformer

+ (void) initialize
{
    [NSValueTransformer setValueTransformer:[[self alloc] init] 
                                    forName:@"ArrayIsEmptyTransformer"];
}

+ (Class)transformedValueClass
{
	return [NSArray class];
}

+ (BOOL)allowsReverseTransformation
{
	return NO;
}

- (id)transformedValue:(id)value
{
	if ([value count]) return [NSNumber numberWithBool:NO];
	return [NSNumber numberWithBool:YES];
}

@end

@implementation ArrayIsNotEmptyTransformer

+ (void) initialize
{
    [NSValueTransformer setValueTransformer:[[self alloc] init] 
                                    forName:@"ArrayIsNotEmptyTransformer"];
}

+ (Class)transformedValueClass
{
	return [NSArray class];
}

+ (BOOL)allowsReverseTransformation
{
	return NO;
}

- (id)transformedValue:(id)value
{
	if ([value count]) return [NSNumber numberWithBool:YES];
	return [NSNumber numberWithBool:NO];
}

@end

@implementation ArrayHasMultipleTransformer

+ (void) initialize
{
    [NSValueTransformer setValueTransformer:[[self alloc] init] 
                                    forName:@"ArrayHasMultipleTransformer"];
}

+ (Class)transformedValueClass
{
	return [NSArray class];
}

+ (BOOL)allowsReverseTransformation
{
	return NO;
}

- (id)transformedValue:(id)value
{
	if ([value count] > 1) return [NSNumber numberWithBool:YES];
	return [NSNumber numberWithBool:NO];
}

@end

@implementation ArrayHasNotMultipleTransformer

+ (void) initialize
{
    [NSValueTransformer setValueTransformer:[[self alloc] init] 
                                    forName:@"ArrayHasNotMultipleTransformer"];
}

+ (Class)transformedValueClass
{
	return [NSArray class];
}

+ (BOOL)allowsReverseTransformation
{
	return NO;
}

- (id)transformedValue:(id)value
{
	if ([value count] > 1) return [NSNumber numberWithBool:NO];
	return [NSNumber numberWithBool:YES];
}

@end

@implementation BoolToRedColorTransformer

+ (void) initialize
{
    [NSValueTransformer setValueTransformer:[[self alloc] init] 
                                    forName:@"BoolToRedColorTransformer"];
}

+ (Class)transformedValueClass
{
	return [NSNumber class];
}

+ (BOOL)allowsReverseTransformation
{
	return NO;
}

- (id)transformedValue:(id)value
{
	if ( [value intValue] ) {
		return [NSColor redColor];
	}
	return [NSColor blackColor];
}

@end

@implementation BoolToBlueColorTransformer

+ (void) initialize
{
    [NSValueTransformer setValueTransformer:[[self alloc] init] 
                                    forName:@"BoolToBlueColorTransformer"];
}

+ (Class)transformedValueClass
{
	return [NSNumber class];
}

+ (BOOL)allowsReverseTransformation
{
	return NO;
}

- (id)transformedValue:(id)value
{
	if ( [value intValue] ) {
		return [NSColor blueColor];
	}
	return [NSColor blackColor];
}

@end

@implementation NSDateToSimpleNSStringTransformer

+ (void) initialize
{
    [NSValueTransformer setValueTransformer:[[self alloc] init] 
                                    forName:@"NSDateToSimpleNSStringTransformer"];
}

+ (Class)transformedValueClass
{
	return [NSDate class];
}

+ (BOOL)allowsReverseTransformation
{
	return NO;
}

- (id)transformedValue:(id)value
{
	NSString *str = [NSDateFormatter localizedStringFromDate:value 
												   dateStyle:kCFDateFormatterShortStyle
												   timeStyle:kCFDateFormatterMediumStyle];
	return str;
}

@end
